//
//  GuidViewController.swift
//  Neufood
//
//  Created by Mac  on 2017/9/20.
//  Copyright © 2017年 Mac . All rights reserved.
//

import UIKit

class GuidViewController: UIViewController,UIScrollViewDelegate {
    var scrollview = UIScrollView()
    var harry = ["0.jpg","1.jpg","2.jpg"]
    override func viewDidLoad() {
        super.viewDidLoad()
        self.scrollview.delegate = self
        self.scrollview.frame = self.view.bounds
        self.scrollview.backgroundColor = UIColor.white
        self.scrollview.isPagingEnabled = true
        self.scrollview.showsVerticalScrollIndicator = false
        self.scrollview.showsHorizontalScrollIndicator = false
        self.scrollview.scrollsToTop = false
        //设置滚动的范围
        self.scrollview.contentSize = CGSize(width: self.view.frame.width*3, height: 0)
        //p1.frame = CGRect(x:30,y:50,width:300,height:300)
        
        //self.scrollview.addSubview(p1)
        
        for i in 0..<harry.count {
            let hImageViews = UIImageView(image: UIImage(named: "\(i).jpg"))
            hImageViews.frame = CGRect(x:self.view.frame.size.width*CGFloat(i),y:50,width:self.view.frame.size.width,height:500)
            
            self.scrollview.addSubview(hImageViews)
        }
        
        
        self.view.addSubview(self.scrollview)
        

        // Do any additional setup after loading the view.
    }
    
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let second = self.view.frame.size.width*CGFloat(harry.count-1)
        if(self.scrollview.contentOffset.x > second)
        {
            let mainStroyboard = UIStoryboard(name: "Main", bundle: nil)
            let viewController:ViewController = mainStroyboard.instantiateViewController(withIdentifier: "mainstoryboard") as! ViewController
            self.present(viewController, animated: true, completion: nil)
    
            
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
